package cn.tedu.hhmc.patient_disease_relation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.tedu.hhmc.base.response.JsonResult;
import cn.tedu.hhmc.patient_disease_relation.pojo.entity.PatientDiseaseRelation;
import cn.tedu.hhmc.patient_disease_relation.pojo.vo.PatientDiseaseRelationVO;
import cn.tedu.hhmc.patient_disease_relation.service.IPatientDiseaseRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 病人-疾病关联Controller
 * 
 * @author ruoyi
 * @date 2024-12-05
 */
@RestController
@RequestMapping("/hhmc/relation")
public class PatientDiseaseRelationController
{
    @Autowired
    private IPatientDiseaseRelationService patientDiseaseRelationService;

    /**
     * 查询病人-疾病关联列表
     */
    @GetMapping("/list")
    public JsonResult list(PatientDiseaseRelation patientDiseaseRelation)
    {
        List<PatientDiseaseRelationVO> list = patientDiseaseRelationService.selectPatientDiseaseRelationList(patientDiseaseRelation);
        return JsonResult.ok(list);
    }

    /**
     * 导出病人-疾病关联列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, PatientDiseaseRelation patientDiseaseRelation)
    {
        List<PatientDiseaseRelationVO> list = patientDiseaseRelationService.selectPatientDiseaseRelationList(patientDiseaseRelation);
//        ExcelUtil<PatientDiseaseRelation> util = new ExcelUtil<PatientDiseaseRelation>(PatientDiseaseRelation.class);
//        util.exportExcel(response, list, "病人-疾病关联数据");
    }

    /**
     * 获取病人-疾病关联详细信息
     */
    @GetMapping(value = "/{patientId}")
    public JsonResult getInfo(@PathVariable("patientId") Long patientId)
    {
        return JsonResult.ok(patientDiseaseRelationService.selectPatientDiseaseRelationByPatientId(patientId));
    }

    /**
     * 新增病人-疾病关联
     */
    @PostMapping
    public JsonResult add(@RequestBody PatientDiseaseRelation patientDiseaseRelation)
    {
        patientDiseaseRelationService.insertPatientDiseaseRelation(patientDiseaseRelation);
        return JsonResult.ok();
    }

    /**
     * 修改病人-疾病关联
     */
    @PutMapping
    public JsonResult edit(@RequestBody PatientDiseaseRelation patientDiseaseRelation)
    {
        patientDiseaseRelationService.updatePatientDiseaseRelation(patientDiseaseRelation);
        return JsonResult.ok();
    }

    /**
     * 删除病人-疾病关联
     */
	@DeleteMapping("/{patientIds}")
    public JsonResult remove(@PathVariable Long[] patientIds)
    {
        patientDiseaseRelationService.deletePatientDiseaseRelationByPatientIds(patientIds);
        return JsonResult.ok();
    }
}
